Readonly
This crate provides an attribute macro to expose struct fields that are readable and writable from within the same module but readable only outside the module.
[]
= "0.2"
Syntax
Place #[readonly::make]
on a braced struct or tuple struct. This will make all
fields of the struct publicly readable according to their individual visibility
specifiers, but not writable from other modules.
The error appears as follows.
error[E0594]: cannot assign to data in a dereference of `m::S`
--> readme.rs:21:5
|
21 | s.n += 1;
| ^^^^^^^^ cannot assign
Optionally, place #[readonly]
on individual struct fields to make just those
fields publicly readable, without affecting other fields of the struct.